package com.qunar.wan.web.controller;

import com.qunar.wan.common_api.model.SubClassify;
import com.qunar.wan.common_api.model.UserClassify;
import com.qunar.wan.common_api.service.UserClassifyService;
import com.qunar.wan.web.controller.common.AbstractController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * User: meisiqi Date: 13-11-28 Time: 上午11:58
 */
@Controller
@RequestMapping("/userClassify")
public class UserClassifyController extends AbstractController {
    @Resource
    private UserClassifyService userClassifyService;

    /**
     * 用户添加爱好 (第一次登入和个人中心)
     */
    @RequestMapping("/add")
    @ResponseBody
    public Object addClassify(@RequestParam String classifies, @RequestParam int userId) {
        long start = System.currentTimeMillis();
        userClassifyService.addUserClassifies(classifies, userId);
        return dataJson("", System.currentTimeMillis() - start);
    }

    /**
     * 用户删除爱好 （）
     */
    @RequestMapping("/del")
    @ResponseBody
    public Object delClassify(@RequestParam int subClaId, @RequestParam int userId) {
        long start = System.currentTimeMillis();
        UserClassify uc = new UserClassify(userId, subClaId);
        userClassifyService.updateObj(uc);
        return dataJson("", System.currentTimeMillis() - start);
    }

    /**
     * 用户已选爱好
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object listClassify(@RequestParam int userId) {
        long start = System.currentTimeMillis();
        List<SubClassify> list = userClassifyService.selectByuserId(userId);
        return dataJson(list, System.currentTimeMillis() - start);
    }

}
